﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MISAPP.MISInterface;

public partial class View_CIB_CIB003 : ViewMatrix
{
    string option = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        limit();
        Title = "兩個月份走勢表";
        criteriaList = new string[] { "Criteria", "ExclusiveOfAccount", "Money", "Sign" };
        serviceName = "MISAPP.Classify.Service.Service_CIB003";
        if (!IsPostBack)
        {
            FillCriteria("GetCriteriaData", "SetData");
        }

    }

    protected void btn_Execute_Click(object sender, EventArgs e)
    {
        Button btn = sender as Button;
        string nextPage;
        nextPage = "CIB003_1.aspx?C={0}";
        switch (btn.ID)
        {
            case "btn_Execute":
                option = "1";
                break;
            case "btn_Execute2":
                option = "2";
                break;
            default:
                option = "3";
                break;
        }
        nextPage = string.Format(nextPage, option);
        Execute();
        Server.Transfer(nextPage);
    }

    protected void Execute()
    {
        string money = "1";

        if (chkMoney.Checked == true)
        {
            Int32 iMoney = 100000000;
            money = txtThanMoney.Text.Length == 0 ? iMoney.ToString()
                : Convert.ToString(Convert.ToInt16(txtThanMoney.Text) * iMoney);
        }

        List<iSelectList> CriteriaList = GetSelectCLB();
        List<iSelectList> yyyyList = new List<iSelectList>();
        List<iSelectList> newList = new List<iSelectList>();
        string strYYYY = string.Empty;
        foreach (iSelectList sel in CriteriaList)
        {
            if (sel.GetField().Length > 4)
            {
                if (sel.GetField().Substring(0, 4).Equals("YYYY"))
                {
                    if (strYYYY == string.Empty)
                    {
                        strYYYY = sel.GetField().Substring(0, sel.GetField().Length - 1);
                    }
                    if (rdoDateSeason1.Checked)
                    {
                        yyyyList.Add(sel);
                    }
                }
                else
                {
                    if (!sel.GetField().Substring(0, 4).Equals("Seas"))
                    {
                        newList.Add(sel);
                    }
                }

                if ((rdoDateSeason2.Checked) &
                             (sel.GetField().Substring(0, 4).Equals("Seas")))
                {
                    strYYYY = "YYYYMM";
                    yyyyList.Add(sel);
                }
            }
            else
            {
                newList.Add(sel);
            }
        }
        iSelectList newSele = Utility.GetServiceObject("MISAPP.Classify.Service.SelectList")
                                     as iSelectList;

        newSele.SetField(strYYYY);
        newSele.SetReverse(false);
        foreach (iSelectList sel in yyyyList)
        {
            newSele.AddToList((string)sel.GetListArray().GetValue(0));
        }
        newList.Add(newSele);


        Session["Criteria"] = newList;
        Session["ExclusiveOfAccount"] = Utility.GetExclusiveAccont(chk_公庫.GetSelectValue());
        Session["Money"] = money;
        Session["PageSize"] = ddlGVPageSizeSelect1.GetSelectPageSize();
        Session["Sign"] = drpSign.SelectedValue;
        Context.Items.Add("Money", money);

    }

}
